﻿using System.Windows;
using theeg.GraphWpf.Models;

namespace theeg.GraphWpf.Arrangement
{
    internal static class RoutingMediator
    {
        /// <summary>
        /// </summary>
        /// <returns></returns>
        internal static void CalculateRouting(Transition transition)
        {
            switch (transition.RoutingStyle)
            {
                case RoutingStyle.FreeHand:
                case RoutingStyle.FreeHandHorizontal:
                case RoutingStyle.FreeHandVertical:
                    CustomRouting.CalculateRoutingPoints(transition);
                    break;

                case RoutingStyle.TwoPointHorizontal:
                    ThreePointRouting.CalculateRoutingPoints(transition, RoutingConfiguration.Horizontal);
                    break;

                case RoutingStyle.TwoPointVertical:
                    ThreePointRouting.CalculateRoutingPoints(transition, RoutingConfiguration.Vertical);
                    break;

                case RoutingStyle.BusHorizontal:
                    BusRouting.CalculateRoutingPoints(transition, RoutingConfiguration.Horizontal);
                    break;

                case RoutingStyle.BusVertical:
                    BusRouting.CalculateRoutingPoints(transition, RoutingConfiguration.Vertical);
                    break;
            }
        }

        internal static Point OrientationToEndpoint(ConnectorOrientation orientation, INode node)
        {
            switch (orientation)
            {
                case ConnectorOrientation.Left:
                    return new Point(node.Left, node.Top + node.Height * 0.5);
                case ConnectorOrientation.Bottom:
                    return new Point(node.Left + node.Width * 0.5, node.Top + node.Height);
                case ConnectorOrientation.Right:
                    return new Point(node.Left + node.Width, node.Top + node.Height * 0.5);
                case ConnectorOrientation.Top:
                    return new Point(node.Left + node.Width * 0.5, node.Top);
                default:
                    return new Point(node.CenterX, node.CenterY);
            }
        }
    }
}
